<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <input type="button" value="修改书名" @click="changeBook">
        <ul>
            <li v-for="item in books">{{item}}</li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>

    <script>
        let vm = new Vue({
            el: "#app",
            data: {
               books:["三国演义","西游记","红楼梦"],
               str:""
            },
            methods:{
                changeBook(){
                    // 非响应式的情况：
                    // 1、使用数组的下标修改数据
                    // this.books[1]="水浒传";
                    // 替代方案
                    // this.books.splice(1,1,"水浒传");
                    // this.$set(this.books,1,"水浒传")

                    // console.log(this.books);

                    // 2、修改数组的长度
                    // this.books.length = 5;
                    // console.log(this.books);
                    // console.log(this.books.length);

                    // 3、给对象增加属性
                    // this.str="ddd";
                    // this.$set(this,str,"ddd");//不建议这么做，直接定义在data里就行。



                    this.books[1]="水浒传";
                    this.$forceUpdate();//强制刷新                    
                }
            }
        })

    </script>
</body>

</html>